<%@ page contentType="text/html; charset=utf-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn"%>
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form"%>
<%@ taglib uri="http://www.springframework.org/tags" prefix="spring"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>
<c:if test="${notfound != null}">
	<div class="error_box">
		<spring:message code="notfound.producer" />
	</div>
</c:if>

<c:if test="${notfound == null}">
	<h2>
		<spring:message code="manage.producer" />
	</h2>

	<c:if test="${successfulMessage != null}">
		<div class="valid_box">
			<spring:message code="successful.deleteproducer" />
		</div>
	</c:if>

	<c:url value="/admin/producer" var="actionurl" />
	<div class="sidebar_search">
		<form:form action="${actionurl}" method="get" commandName="query">
			<form:input path="keyWord" cssClass="search_input" />
			<input type="submit" class="search_submit" value="" />
		</form:form>
	</div>

	<table id="rounded-corner">
		<thead>
			<tr>
				<th scope="col" class="rounded-company"><spring:message
						code="id" /></th>
				<th scope="col" class="rounded"><spring:message code="producer" /></th>
				<th scope="col" class="rounded"><spring:message
						code="description" /></th>
				<th scope="col" class="rounded"><spring:message code="edit" /></th>
				<th scope="col" class="rounded-q4"><spring:message
						code="delete" /></th>
			</tr>
		</thead>
		<tfoot>
			<tr>
				<td colspan="4" class="rounded-foot-left"><em><spring:message
							code="total" />: <strong>${resultPage.numItems}</strong> <spring:message
							code="producer" /> </em></td>
				<td class="rounded-foot-right">&nbsp;</td>

			</tr>
		</tfoot>
		<tbody>
			<c:forEach var="resultItem" items="${resultPage.result}">
				<tr>
					<td style="text-align: right;">${resultItem.id }</td>
					<td>${resultItem.name }</td>
					<td>${resultItem.description }</td>
					<td><a
						href="<c:url value="/admin/producer/edit?pid=${resultItem.id}"/>"><img
							src="<c:url value="/images/user_edit.png"/>" alt="" title=""
							border="0" /></a></td>
					<td><a
						href="<c:url value="/admin/producer/delete?pid=${resultItem.id}"/>"
						class="ask"><img src="<c:url value="/images/trash.png"/>"
							alt="" title="" border="0" /></a></td>
				</tr>
			</c:forEach>
		</tbody>
	</table>

	<c:if test="${fn:length(resultPage.result) > 0}">
		<div>
			<ul id="pagination-digg">
				<c:choose>
					<c:when test="${resultPage.currentPage == 0}">
						<li class="previous-off">« <spring:message code="previous" /></li>
					</c:when>
					<c:otherwise>
						<li class="previous"><a
							href="<c:url value="/admin/producer?${pageURL}&page=${resultPage.currentPage + 1 - 1}"/>">«
								<spring:message code="previous" />
						</a></li>
					</c:otherwise>
				</c:choose>

				<c:choose>
					<c:when test="${resultPage.numPage < 10}">
						<c:set var="firstIndexPage" value="0" scope="request" />
						<c:set var="lastIndexPage" value="${resultPage.numPage - 1}"
							scope="request" />
					</c:when>
					<c:otherwise>
						<c:choose>
							<c:when
								test="${resultPage.currentPage + 4 <= resultPage.numPage - 1 && resultPage.currentPage - 5 >= 0}">
								<c:set var="firstIndexPage"
									value="${resultPage.currentPage - 5}" scope="request" />
								<c:set var="lastIndexPage" value="${resultPage.currentPage + 4}"
									scope="request" />
							</c:when>
							<c:otherwise>
								<c:if test="${resultPage.currentPage - 5 < 0}">
									<c:set var="firstIndexPage" value="0" scope="request" />
									<c:set var="lastIndexPage" value="9" scope="request" />
								</c:if>
								<c:if
									test="${resultPage.currentPage + 4 > resultPage.numPage - 1}">
									<c:set var="firstIndexPage"
										value="${resultPage.numPage - 1 - 9}" scope="request" />
									<c:set var="lastIndexPage" value="${resultPage.numPage - 1}"
										scope="request" />
								</c:if>
							</c:otherwise>
						</c:choose>
					</c:otherwise>
				</c:choose>

				<c:forEach var="index" begin="${firstIndexPage}"
					end="${lastIndexPage}">
					<c:choose>
						<c:when test="${index == resultPage.currentPage}">
							<li class="active">${index + 1}</li>
						</c:when>
						<c:otherwise>
							<li><a
								href="<c:url value="/admin/producer?${pageURL}&page=${index + 1}"/>">${index
									+ 1}</a></li>
						</c:otherwise>
					</c:choose>
				</c:forEach>

				<c:choose>
					<c:when test="${resultPage.currentPage == (resultPage.numPage-1)}">
						<li class="next-off"><spring:message code="next" /> »</li>
					</c:when>
					<c:otherwise>
						<li class="next"><a
							href="<c:url value="/admin/producer?${pageURL}&page=${resultPage.currentPage + 1 + 1}"/>"><spring:message
									code="next" /> »</a></li>
					</c:otherwise>
				</c:choose>

			</ul>
		</div>
	</c:if>

	<a href="<c:url value="/admin/producer/edit"/>" class="bt_green"><span
		class="bt_green_lft"></span><strong><spring:message
				code="add" /></strong><span class="bt_green_r"></span></a>
</c:if>